define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'staff/staffpiclist/index',
                    add_url: 'staff/staffpiclist/add',
                    edit_url: 'staff/staffpiclist/edit',
                    del_url: 'staff/staffpiclist/del',
                    multi_url: '',
                    table: 'page',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url+'/id/'+table.data('id'),
                sortName: 'weight',
                columns: [
                    [
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'src', title: __('Image'), formatter: Table.api.formatter.image, operate: false},
                        {field: 'weight', title: __('Weight'), operate: false},
                        {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                //普通搜索
                commonSearch: false,
                searchFormVisible: false,
                titleForm: '', //为空则不显示标题，不定义默认显示：普通搜索
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            //增加图片
            $(document).on("click", ".btn-addpic", function () {
                Backend.api.open('staff/staffpiclist/addpic/id/' + $(this).data('id'), __('addpic'));
            });
            //刷新表单
            $(document).on("click", ".btn-refreshpic", function () {
                table.bootstrapTable('refresh');
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        addpic: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});